package com.jgp.security.controller;

import com.jgp.security.service.SecRoleResourceService;
import com.jgp.sys.controller.JGPBackController;
import com.jgp.sys.ui.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2020/9/29
 */
@RestController
@RequestMapping("/security/role-res-api-ctl")
public class RoleResApiController extends JGPBackController {
    
    @Autowired
    private SecRoleResourceService roleResourceService;
    
    @RequestMapping("add-res")
    public Result addRes(Long roleId,String resId){
        roleResourceService.addRoleRes(roleId,resId);
        return ajaxRe(true);
    }
    
    @RequestMapping("remove-res")
    public Result removeRes(Long roleId,String resId){
        roleResourceService.removeRoleRes(roleId,resId);
        return ajaxRe(true);
    }
    
    @RequestMapping("query-res")
    public Result queryRes(Long roleId){
        List<String> resources = roleResourceService.queryResourceIds(roleId);
        return ajaxReData("resources",resources);
    }
}